package logic.algorithm.aco;

import javax.swing.JFrame;
import logic.objects.Connection;
import logic.objects.Problem;
import logic.service.PheromonService;

public class ElitistAS extends AntSystem {

	double e;

	@Override
	protected void initializeParameters() {
		beta = 5.0;
		alpha = 1.0;
		roh = 0.5;
		e = problem.getNodes().size();
		tau0 = (e + problem.getNodes().size())
				/ (roh * PheromonService
						.getNearestNeighborShortedTourValue(problem));
	}

	public ElitistAS(Problem problem, JFrame frame) {
		super(problem, frame);
	}

	@Override
	protected void updatePheromon() {
		for (int i = 0; i < problem.getConnections().getSizeX(); i++) {
			for (int j = 0; j < problem.getConnections().getSizeY(); j++) {
				if (i != j) {
					Connection con = problem.getConnections().get(i, j);
					con.setPheromon(con.getPheromon() * (1.0 - roh));
				}
			}
		}
		for (Ant ant : ants) {
			updatePheromonByAnt(ant, 1.0);
		}
		updatePheromonByBestSoFarSolution(e);

		problem.getConnections().updateMaxPheromon();
	}

}
